import { common } from '@/api'
import { reactive } from 'vue'
import type { IDataDialog, ISearchListData } from '@/components/search/types'

export const data = reactive<IDataDialog>({
    isShowDialog: false,
    input: '',
    allStoreList: [],
    activeIdx: 0,
    searchLists: undefined,
    activeSearchIdx: 0,
})

export const resultData = () => {
    return common.headerSearch(data.input)
}

// 数组去重
export const removeDuplicate = (arr: ISearchListData[]) => {
    return arr.filter(
        (obj, index) =>
            arr.findIndex(
                (item) =>
                    item.url === obj.url &&
                    item.title === obj.title &&
                    item.illustrate === obj.illustrate,
            ) === index,
    )
}
